import http from './interface'
import baseUrl from '../api/index'
/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */

// 单独导出(测试接口) import {test} from '@/common/vmeitime-http/'
export const uniHttpGet = (url,data) => {
	 http.config.baseUrl =  baseUrl.server_base_url;
	 
	 console.log("get请求"+baseUrl.server_base_url)
	 if(data == null){
		 data = new Object();
	 }
	 data.token =  uni.getStorageSync("token");
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			
		},
		config.data =  data
	} 
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....'+response.statusCode)
		//判断返回状态 执行相应操作
		if(response.statusCode != 200){
			uni.showToast({
				icon: 'none',
				title: '服务器异常！'
			});
		}
		return response;
	}
    return http.request({
        url: url,
		dataType: 'text',
		method: 'GET', 
        data,
    })
}

export const uniHttpPost = (url,data) => {
	 http.config.baseUrl =  baseUrl.server_base_url;
	 console.log("post请求"+baseUrl.server_base_url);
	 console.log("token"+uni.getStorageSync("token"));
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"AUTH": uni.getStorageSync("token")
		}
	} 
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....'+JSON.stringify(response))
		//判断返回状态 执行相应操作
		if(response.statusCode != 200){
			uni.showToast({
				icon: 'none',
				title: '服务器异常！'
			});
		}
		return response;
	}
    return http.request({
        url: url,
		method: 'POST', 
        data,
    })
}

// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	uniHttpPost,
	uniHttpGet,
}